﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

namespace DBComparer.Common
{
    class Connection
    {
        string _connectionString = "";

        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }

        public SqlConnection GetConnection() 
        {
            return new SqlConnection(ConnectionString);
        
        }

        public bool Check(out string argError) 
        {
            argError = "";
            bool _isConnected = false;
            SqlConnection Connection = GetConnection();

            try
            {
                Connection.Open();
                if (Connection.State == ConnectionState.Open)
                    _isConnected = true;
            }
            catch (Exception ex)
            {
                argError = ex.Message;
            }
            finally 
            {
                Connection.Close();
            }

            return _isConnected;
        }

    }
}
